package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.MemberMapper;
import com.itheima.mapper.OrderMapper;
import com.itheima.mapper.ReportMapper;
import com.itheima.pojo.Order;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <h3>health94_pareant</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-03-31 22:03
 **/
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Map setMealReport() {
        //获取order表中的预约数量及其名字
        List<Map<String,Object>> orderCount = reportMapper.getOrderCount();
        //存放名字的list
        LinkedList<String> allName = new LinkedList<>();
        for (Map map : orderCount) {
            String name = (String)map.get("name");
            allName.add(name);
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("allName", allName);
        map.put("orderCount", orderCount);
        return map;
    }

    @Override
    public Map businessReport() {

        HashMap<String, Object> map = new HashMap<>();
        //报告日期 reportDate
        Date today = DateUtils.getToday();
        String reportDate = new SimpleDateFormat("yyyy-MM-dd").format(today);
        //今日新增会员数
        int todayNewMember = memberMapper.countNewMemberByDate(reportDate);
        //总会员数
        int totalMember = memberMapper.memberCount();
        //本周新增会员数
        Date firstDayOfWeek = DateUtils.getFirstDayOfWeek(today);
        int thisWeekNewMember = memberMapper.countNewMemberMoreDate(firstDayOfWeek);    //这里可以用日期直接传进去 yyyy-MM-dd 00;00;00
        //本月新增会员数
        Date firstDay4ThisMonth = DateUtils.getFirstDay4ThisMonth();
        int thisMonthNewMember = memberMapper.countNewMemberMoreDate(firstDay4ThisMonth);
        //今日预约数
        int  todayOrderNumber = orderMapper.countOrderByDate(reportDate);
        // 今日到诊数
        int todayVisitsNumber = orderMapper.countOrderStatus(reportDate);
        //本周预约数
        int thisWeekOrderNumber = orderMapper.countOrderMoreDate(firstDayOfWeek);    //这里可以用日期直接传进去 yyyy-MM-dd 00;00;00
        //本月预约数
        int thisMonthOrderNumber = orderMapper.countOrderMoreDate(firstDay4ThisMonth);
        //本周到诊数
        int thisWeekVisitsNumber = orderMapper.countOrderStatusMoreDate(firstDayOfWeek);    //这里可以用日期直接传进去 yyyy-MM-dd 00;00;00
        //本月到诊数
        int thisMonthVisitsNumber = orderMapper.countOrderStatusMoreDate(firstDay4ThisMonth);
        //显示4个热门套餐
        List<Map> hotSetmeal = orderMapper.hostSetmeal();

        map.put("reportDate", reportDate);
        map.put("todayNewMember", todayNewMember);
        map.put("totalMember", totalMember);
        map.put("thisWeekNewMember", thisWeekNewMember);
        map.put("thisMonthNewMember", thisMonthNewMember);
        map.put("todayOrderNumber", todayOrderNumber);
        map.put("todayVisitsNumber", todayVisitsNumber);
        map.put("thisWeekOrderNumber", thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber", thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
        map.put("hotSetmeal", hotSetmeal);

        return map;
    }
}
